var g$mobile = $(window).width() < 640 || navigator.userAgent.match(/mobile/i) != null;

//if (g$mobile) {
//    var m = document.createElement("META");
//    m.setAttribute("name", "viewport");
//    m.setAttribute("content", "width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no");
//    document.head.appendChild(m);
//}

$(window).resize(function () {
    var screen = $(window).width() < 640 || navigator.userAgent.match(/mobile/i) != null;
    if ($('body').height() < $(window).height()) {
        $('#main').css('min-height', $(window).height() - 280)
    }
    if (g$mobile != screen) {
        g$mobile = screen;
    } else {
        //noop
    }
});

$(document).ready(function () {
    var downloadApp = function () {

        var isWX = navigator.userAgent.match(/MicroMessenger/i) != null;
        var isIOS = navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) != null;
        var isPC = navigator.userAgent.match(/mobile/i) == null;

        var HREF = {
            wx: 'http://a.app.qq.com/o/simple.jsp?pkgname=com.weimi.mzg.ws',
            ios: 'https://itunes.apple.com/cn/app/wen-shen-da-ka-zui-hao-wen/id1022212399?mt=8',
            adr: 'http://a.app.qq.com/o/simple.jsp?pkgname=com.weimi.mzg.ws',
            pc: 'http://www.wenshendaka.com/'
        };

        if (isWX) {
            location.href = HREF.wx;
        }
        else if (isIOS) {
            location.href = HREF.ios;
        }
        else if (isPC) {
            location.href = HREF.pc;
        }
        else {
            location.href = HREF.adr;
        }
    };

    $('.banner').click(downloadApp);

    if ($('body').height() < $(window).height()) {
        $('#main').css('min-height', $(window).height() - 280)
    }

    if (navigator.userAgent.match(/mobile/i) != null) {

        var btnDownload = {
            isShow: false,
            $: $('.btn-download'),
            loop: function () {
                if (window.scrollY > 190 && btnDownload.isShow == false) {
                    btnDownload.isShow = true;
                    $('.btn-download').fadeIn(500);
                }

                if (window.scrollY < 190 && btnDownload.isShow == true) {
                    btnDownload.isShow = false;
                    $('.btn-download').fadeOut(500);
                }
            }
        };

        btnDownload.$.click(downloadApp);

        $('.tips').fadeIn(500);
        setTimeout(function () {
            $('.tips').fadeOut(500);
        }, 5000);

        setInterval(btnDownload.loop, 1000)

    }
});